#include "StdAfx.h"
#include "Sequence.h"

CSequence::CSequence(void)
{
	pSeq = 0;
}

CSequence::~CSequence(void)
{
	if(pSeq)
		delete [] pSeq;
}

void CSequence::Init( tagSeqInfo& seqInfo )
{
	this->strSeqName = seqInfo.strSeqName;
	this->strSeqPath = seqInfo.strSeqPath;
	this->strBeginTime = seqInfo.strBeginTime;
	this->strInterval = seqInfo.strInterval;
}

bool CSequence::LoadFile()
{
	char tmpFileName[255] = {0};
	if(wcslen(strSeqPath.c_str()) >= 255) return false;	
	WideCharToMultiByte(CP_ACP, 0, strSeqPath.c_str(), wcslen(strSeqPath.c_str()), tmpFileName, 255, 0, 0);

	FILE *stream = 0;
	if((stream = fopen(tmpFileName, "r" )) == 0)
		return false;

	if(fseek(stream, 0, SEEK_END) != 0)
	{
		fclose(stream);
		return false;
	}

	int nLength = ftell(stream);

	if(nLength % 3 != 0)
	{		
		fclose(stream);
		return false;
	}
	nCount = nLength / 3;

	pSeq = new unsigned char[nLength];
	if(!pSeq) return false;

	if(fseek(stream, 0, SEEK_SET) != 0)
	{
		fclose(stream);
		return false;
	}

	fread(pSeq, sizeof(char), nLength, stream);

	fclose(stream);
	return true;
}

bool CSequence::CanStart()
{
	return true;
}

